//
// Created by PC on 2023/6/26.
// 星卯科技公众号提供的答案
//


#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;
char c[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
string str[30];

//进制转换
int trans(string s)
{
    int r = 0;
    switch (s[0])
    {
        case 'A':
            r += 10 * 16;
            break;
        case 'B':
            r += 11 * 16;
            break;
        case 'C':
            r += 12 * 16;
            break;
        case 'D':
            r += 13 * 16;
            break;
        case 'E':
            r += 14 * 16;
            break;
        case 'F':
            r += 15 * 16;
            break;
        default:
            r += (s[0] - '0') * 16;
            break;
    }
    switch (s[1])
    {
        case 'A':
            r += 10;
            break;
        case 'B':
            r += 11;
            break;
        case 'C':
            r += 12;
            break;
        case 'D':
            r += 13;
            break;
        case 'E':
            r += 14;
            break;
        case 'F':
            r += 15;
            break;
        default:
            r += (s[1] - '0');
            break;
    }
    return r;
}

//减法返回绝对值
int sub(string s, string t)
{
    int x = trans(s), y = trans(t), r = x - y;
    return r >= 0 ? r : -r;
}

//找到最小的绝对值
string fun(string s, vector<string> v)
{
    string temp = "";
    int min_sub = 10000;
    int i = 0, j;
    for (auto it = v.begin(); it != v.end(); it++, i++)
    {
        if (min_sub > sub(s, *it))
        {
            min_sub = sub(s, *it);
            j = i;
        }
    }
    temp += c[j];
    return temp;
}

bool cmp(const pair<string, int> &s, const pair<string, int> &t)
{
    if (s.second == t.second) return s.first < t.first;
    else return s.second > t.second;
}

int main()
{
    int n, cnt;
    cin >> n;
    string s, temp;
    map<string, int> m;//使用map容器，防止同样的元素多次插入
    vector<pair<string, int>> vec;
    vector<string> v;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        str[i] = s;
        cnt = 0;
        temp = "";
        for (int j = 0; j < s.size(); j++)
        {
            cnt++;
            temp += s[j];
            if (cnt == 2)
            {
                m[temp]++;
                cnt = 0;
                temp = "";
            }
        }
    }

    for (auto it = m.begin(); it != m.end(); it++)
        vec.push_back(*it);
    sort(vec.begin(), vec.end(), cmp);
    int i = 0;
    for (auto it = vec.begin(); it != vec.end() && i < 16; it++, i++)
    {
        cout << it->first;
        v.push_back(it->first);
    }
    cout << endl;
    for (int i = 0; i < n; i++)
    {
        s = str[i];
        cnt = 0;
        temp = "";
        for (int j = 0; j < s.size(); j++)
        {
            cnt++;
            temp += s[j];
            if (cnt == 2)
            {
                temp = fun(temp, v);
                cout << temp;
                cnt = 0;
                temp = "";
            }
        }
        cout << endl;
    }
    return 0;
}